<template>
  <div class="innerPageTable-box-OneTwo innerPageTable-out-flex">
     <!-- 搜索区域 -->
    <SelfAdaption>
      <Form
        :model="searchForm"
        ref="modelForm"
        slot="adaption-bar"
        label-position="top"
        class="ivu-form-no-margin-bottom"
        inline
      >
        <Form-item prop="name" :label="$t('module.launchApp.processTitle')">
          <Input
            type="text"
            :maxlength="30"
            v-model.trim="searchForm.name"
            placeholder
            
            @on-enter="search"
          ></Input>
        </Form-item>
        <Form-item prop="taskName" :label="$t('module.launchApp.taskName')">
          <Input
            type="text"
            :maxlength="30"
            v-model.trim="searchForm.taskName"
            placeholder
            
            @on-enter="search"
          ></Input>
        </Form-item>
        <Form-item prop="button" class="search-solt-btn">
           <RPButton optType="search" @click="search" />
           <RPButton optType="reset" @click="reset" />
        </Form-item>
      </Form>
    </SelfAdaption>
    <InnerPageTable ref="modelListTable" :config="tableConfig">
    </InnerPageTable>
  </div>
</template>
<script>
import { getTodoList } from '@api/flowable/appHistory.js'
import { appListColumns } from './columns.js'
import IframeContainer from '@/components/IframeContainer.vue'
export default {
  name: 'menu-resource',
  components: { IframeContainer },
  data() {
    return {
      isButtonDisabled: !this.procTypeId || this.procTypeId === '0',
      searchForm: {
        name: '',
        taskName: ''
      },
      tableConfig: {
        loadDataFn: ({ responseProcess, param }) => {
          getTodoList(param).then(({ data }) => {
            data.currentPage = data.pageNum
            delete data.pageNum
            data.recordCount = data.total
            delete data.total

            data.records.map(item => {
              if (!item.endTime) {
                item.status = this.$t('module.launchApp.inProgress')
              } else {
                item.status = this.$t('module.launchApp.done')
              }
            })

            data.recordList = data.records
            delete data.records

            responseProcess(data)
          })
        },
        columnsFn: appListColumns.bind(this),
        autoFirst: true,
        loading: false,
        initParam: { state: 2 }
      }
    }
  },
  methods: {
    _launchProcess(taskId) {
      let vm = this
      new this.$pageModal(
        IframeContainer,
        {
          attrs: {
            src: '/static/task/workflow/#/task/' + taskId,
            width: 900,
            height: 700
          }
        },
        res => {
          res && vm.search()
        }
      )
    },
    search() {
      //刷新列表
      this.$refs['modelListTable'].load(this.searchForm)
    },
    reset() {
      this.$refs['modelForm'].resetFields()
      this.search()
    }
  }
}
</script>